#ifndef __MY_RADIO_H__
#define __MY_RADIO_H__

#include "main.h"
#include "flash.h"

#define BASIC_LORA_FRE	 433000000
//#define BASIC_LORA_FRE     415200000

#define ADC_LEN 6

#define LORA_TX_OK      0x01 
#define LORA_RX_TIMEOUT 0x02
#define LORA_TX_TIMEOUT 0x03
#define LORA_RX_ERROR   0x04
#define LORA_TX_FIRST   0x05

#pragma pack(1)                  
struct LoraRespData {
	//uint8_t  serve[4];
	uint8_t typ;
	uint8_t len;
	uint8_t net;
	char cli[16];
	uint8_t  thErr;
	uint16_t temp;
	uint16_t humi;
	uint16_t adcs[ADC_LEN];
	uint16_t bat;
	uint16_t rssi;
	uint8_t snr;
	uint8_t crc;
};
#pragma pack()

#define LORA_RESP_LEN 64
struct LoraData {
	volatile uint8_t len;
	uint16_t rssi;
	uint8_t snr;
	uint8_t data[LORA_RESP_LEN];
};

extern void DIO_IRQHandler(void);
extern void Radio_Timer_IRQHandler(void) ;

extern void LoraInit(uint8_t freq, uint8_t baud, uint8_t net, uint8_t power, uint8_t sf, uint8_t cr);
extern int ProcessRadio(struct LoraRespData *data, struct FlashData *conf, uint8_t type);
extern uint8_t CalculateCrc(uint8_t data[], uint8_t size);

#endif
